/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bolao.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.codec.digest.DigestUtils;

/**
 *
 * @author 
 */
public class StringUtil {

    public static String join(Collection s, String delimiter) {
        StringBuilder sb = new StringBuilder();
        Iterator iter = s.iterator();
        while (iter.hasNext()) {
            sb.append(iter.next());
            if (iter.hasNext()) {
                sb.append(delimiter);
            }
        }
        return sb.toString();
    }

    public boolean regexpMatch(String str, String strPattern) {
        Pattern pattern = Pattern.compile(strPattern, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        return matcher.find();
    }

    public String md5(String str) {
        return DigestUtils.md5Hex(str);
    }
}
